package spring.superrun.record.mvc.entity.response;

import spring.superrun.record.mvc.entity.enumlibs.ServiceResultCode;

/**
 * 通用响应泛型模板
 */
/// <summary>
/// 服务层响应实体(泛型)
/// </summary>
/// <typeparam name="T"></typeparam>
public class ServiceResultOfT<T> extends ServiceResult {


    /// <summary>
/// 返回实体
/// </summary>
    private T Entities;

    public T getEntities() {
        return Entities;
    }

    public void setEntities(T entities) {
        Entities = entities;
    }
    /// <summary>
    /// 响应成功
    /// </summary>
    /// <param name="message"></param>
    public void IsSuccess(T entities, String message) {
        setMessage(message);
        setCode(ServiceResultCode.Succeed);
        setEntities(getEntities() == null ? entities : getEntities());
        setSuccess();
    }

    /// <summary>
/// 响应失败
/// </summary>
/// <param name="entities"></param>
/// <param name="code"></param>
/// <param name="message"></param>
    public void IsFailed(T entities, ServiceResultCode code, String message) {
        setMessage(message);
        setCode(code);
        setEntities(entities);
        setSuccess();
    }

    /// <summary>
/// 响应失败
/// </summary>
/// <param name="isReturn"></param>
/// <param name="code"></param>
/// <param name="message"></param>
/// <returns></returns>
    public ServiceResultOfT<T> IsFailed(boolean isReturn, ServiceResultCode code, String message) {
        setMessage(message);
        setCode(code);
        setSuccess();
        return this;
    }

    /// <summary>
/// 带返回值的IsSuccess方法
/// </summary>
/// <param name="entities">实体</param>
/// <param name="message">错误信息</param>
/// <param name="IsReturn">true或false</param>
/// <returns></returns>
    public ServiceResultOfT<T> IsSuccess(boolean IsReturn, T entities, String message) {
        setMessage(message);
        setCode(ServiceResultCode.Succeed);
        setEntities(entities);
        setSuccess();
        return this;
    }

    /// <summary>
/// 响应成功
/// </summary>
/// <param name="message"></param>
    public void IsSuccess(String message) {
        setMessage(message);
        setCode(ServiceResultCode.Succeed);
        setSuccess();
    }
}